$(document).ready(function() {

    /*
     $('#nav').onePageNav({
     filter: ':not(.external)',
     scrollThreshold: 0.25
     });
     */
    var searchUrl1 = "https://www.baidu.com/s?wd=";
    var searchUrl2 = "https://www.amazon.com/s/ref=nb_sb_noss_1?field-keywords=";
    var amazon = "https://www.amazon.com/s/ref=nb_sb_noss_1?field-keywords=";
    var searchContent;
    //搜索框
    $('#btn1').on("click", "a", function (event) {
        var arr, urlArr;
        var that = $(this);
        arr = ['百度一下', '谷歌一下', 'Bing一下', '谷歌翻译'];
        urlArr = ['https://www.baidu.com/s?wd=', 'https://www.google.com/search?q=', 'http://global.bing.com/search?q=', 'https://translate.google.cn/#en/zh-CN/'];
        var actived = that.hasClass("active");
        if (actived) {
            that.removeClass("active");
        } else {
            that.siblings().removeClass("active");
            that.addClass("active");
        }
        searchUrl1 = urlArr[that.index()];
        $('#button1').text(arr[that.index()]);
        $('#searchEngin').val("");
    });
    $('#btn2').on("click", "a", function (event) {
        var arr, urlArr;
        var that = $(this);
        arr = ['AMAZON', '关键词', '1688', '17track'];
        urlArr = [amazon, 'http://sonar-tool.com/zh?query=', 'https://s.1688.com/selloffer/offer_search.htm?keywords=', 'https://t.17track.net/zh-cn#nums='];
        var actived = that.hasClass("active");
        if (actived) {
            that.removeClass("active");
        } else {
            that.siblings().removeClass("active");
            that.addClass("active");
        }
        $('#button2').text(arr[that.index()]);
        if (that.index() == 0) {
            $('.area').show();
            $("#search").addClass("pad");
        } else {
            $('.area').hide();
            $("#search").removeClass("pad");
        }
        $('#button2').text(arr[that.index()]);
        searchUrl2 = urlArr[that.index()];
        $('#search').val("");
    });
    $("#button1").on("click", function () {
        searchContent = $('#searchEngin').val();
        window.open(searchUrl1 + searchContent, '_blank');
    });
    $("#button2").on("click", function () {
        searchContent = $('#search').val();
        window.open(searchUrl2 + searchContent, '_blank');
    });
    //选择国家
    $('.area').on("click", function () {
        var that = $(this);
        that.toggleClass("selected");
        that.find('.selection').toggle();
    });
    $('.selection').on("click", "p", function () {
        var that = $(this);
        var amazonUrl = ['https://www.amazon.com/s/ref=nb_sb_noss_1?field-keywords=', 'https://www.amazon.co.uk/s/ref=nb_sb_noss_1?field-keywords=', 'https://www.amazon.de/s/ref=nb_sb_noss_1?field-keywords=', 'https://www.amazon.co.jp/s/ref=nb_sb_noss_1?field-keywords='];
        amazon = amazonUrl[that.index()];
        searchUrl2 = amazon;
        $("#country").text(that.text());

    });
    //左导航效果
    $('.left_nav').on("click", "li", function () {
        var that = $(this);
        var actived = that.hasClass("active");
        if (actived) {
            return;
        } else {
            that.siblings().removeClass("active");
            that.addClass("active");
            var ele_con = $(that.find('a').data('location'));
            /*滚到预定位置*/
            //console.log(ele_con.get(0).offsetTop);
            $('body,html').animate({scrollTop: ele_con.get(0).offsetTop}, 200);
            //console.log($(that.find('a').attr('href')).html());
        }
    });
    //导航内容
    $('.siteGroup li').hover(function () {
        $(this).find("div.links").show();
    }, function () {
        $(this).find("div.links").hide();
    });
    //tab
    $(".panel-head").on("click", 'li', function () {
        var that = $(this);
        var index = 0;
        var actived = that.hasClass("active");
        if (!actived) {
            that.siblings().removeClass("active");
            that.addClass("active");
            index =that.index();
            $(".panel-content").find('.list').eq(index).addClass("active").siblings().removeClass("active");
            $(".panel-content").find('.list').eq(index).find(".carousel").carousel();
            $(".panel-content").find('.list').eq(index).siblings().find(".carousel").carousel('pause');
        }else{
            return;
        }
    });
    $(window).scroll(function () {
        if ($(this).scrollTop() != 0) {
            $('#toTop').show();
        } else {
            $('#toTop').hide();
        }
    });
    $('#toTop').click(function () {
        $('body,html').animate({scrollTop: 0}, 800);
    });

    $(".right_nav_sm").on("click", function () {
        var that = $(this);
        that.hide();
        $(".right_nav").show();
    });
    $(".right_nav_sm").on("click", function () {
        $(this).hide();
        $(".right_nav").show()
    });
    $(".arrow-d").on("click", function () {
        $(".right_nav_sm").show();
        $(".right_nav").hide();
    });
})